<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>

<body>
    <script>
        //forEach
        let arr = [1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
        let add = 0;
        console.log(arr.forEach((val, index) => {
            add += val
        })
        )

        //filter
        console.log('大于等于5' + arr.filter((val, index) => val >= 5))

        //map
        console.log('翻十倍' + arr.map((val, index) => val * 10))

        //reduce
        let arr_ = [10, 20, 30, 40, 50, 60, 70, 80, 90, 100]
        var newArr_ = arr_.reduce((preVal, curVal, curIndex) => preVal + curVal)
        console.log('十到一百reduce求和' + newArr_)

        let arr100 = []
        arr100.length = 100
        arr100.fill(1, 0, arr100.length)
        let add100 = arr100.reduce((preVal, curVal, curIndex) => {
            return preVal + curIndex + 1
        })
        console.log(add100)
    </script>
</body>

</html>